package top.kaoshanji.p2ch06a;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import top.kaoshanji.u1constant.FileConstant;

import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;

/**
 * 代码清单 p2ch06a-07：创建进程的示例
 * author kaoshanji
 * ^_^
 * create time 2025/1/17 18:10
 */
public class ProcessExample01 {

    private static final Logger logger = LogManager.getLogger(ProcessExample01.class);

    public static void main(String[] args) throws IOException {
        logger.info("...代码清单 p2ch06a-07：创建进程的示例...");

        ProcessBuilder pb = new ProcessBuilder("cmd.exe", "/c", "netstat", "-a");
        Process process = pb.start();
        InputStream input = process.getInputStream();
        Files.copy(input, Paths.get(FileConstant.LOCAL_ROOT_PATH.concat("p2ch06a01-netstat.txt")),
                StandardCopyOption.REPLACE_EXISTING);

    }

}
